from django.db import models

# Create your models here.


# 会员模型
class Users(models.Model):
    username = models.CharField(max_length=30)
    password = models.CharField(max_length=80)
    phone = models.CharField(max_length=11)
    email = models.CharField(max_length=100,null=True)
    sex = models.IntegerField(null=True)
    age = models.IntegerField(null=True)
    pic = models.CharField(max_length=100)
    # 状态 默认0能用  1 禁用 2 删除  
    status = models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)

    class Meta:
        permissions = (
            # 指定生成权限
            ("show_users", "查看会员管理"),
            ("insert_users", "添加会员"),
            ("edit_users", "修改会员"),
            ("del_users", "删除会员"),
        )


# 分类的模型
class Types(models.Model):
    name = models.CharField(max_length=10)
    pid =models.IntegerField()
    path =models.CharField(max_length=50)

    class Meta:
        permissions = (
            # 指定生成权限
            ("show_types", "查看商品分类管理"),
            ("insert_types", "添加商品分类"),
            ("edit_types", "修改商品分类"),
            ("del_types", "删除商品分类"),
        )


# 商品分类
class Goods(models.Model):
    # id tid title price num info  pic status clicknum  addtime 
    tid = models.ForeignKey(to="Types", to_field="id")
    title = models.CharField(max_length=255)
    price = models.FloatField()
    num = models.IntegerField()
    info = models.TextField()
    pic = models.CharField(max_length=100)
        # 0 新上架  1 热卖  2 下架 3 删除 
    status = models.IntegerField(default=0)
    clicknum = models.IntegerField(default=0)
    addtime =models.DateTimeField(auto_now_add=True)

    class Meta:
        permissions = (
            # 指定生成权限
            ("show_goods", "查看商品管理"),
            ("insert_goods", "添加商品"),
            ("edit_goods", "修改商品"),
            ("del_goods", "删除商品"),
        )



# 地址模型
class Address(models.Model):
    uid = models.ForeignKey(to="Users", to_field="id")
    addressname = models.CharField(max_length=20)
    address = models.CharField(max_length=100)
    addressphone = models.CharField(max_length=11)
    # False 普通地址  True默认地址
    status = models.BooleanField(default=False)

    class Meta:
        permissions = (
            # 指定生成权限
            ("show_address", "查看地址管理"),
            ("insert_address", "添加地址"),
            ("edit_address", "修改地址"),
            ("del_address", "删除地址"),
        )


# 订单
class Order(models.Model):

    uid = models.ForeignKey(to="Users",to_field="id")
    # 地址外键
    aid = models.ForeignKey(to="Address",to_field="id")
    totalprice = models.FloatField()
    addtime = models.DateTimeField(auto_now_add=True)
    status = models.IntegerField(default=0)

    class Meta:
        permissions = (
            # 指定生成权限
            ("show_order", "查看订单管理"),
            ("insert_order", "添加订单"),
            ("edit_order", "修改订单"),
            ("del_order", "删除订单"),
        )



# 订单详情
class OrderInfo(models.Model):
    orderid = models.ForeignKey(to="Order",to_field="id")
    goodsid  = models.ForeignKey(to="Goods",to_field="id")
    num = models.IntegerField()
    price = models.FloatField()



